package yxy.game.pm2.command.shop;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.MerchantMessage;
import yxy.game.pm2.module.shop.handle.MerchantHandle;

/** 神秘商人 神秘商人界面 */
@MessageType(proto = Command.Merchant, classtype = MerchantMessage.MerchantRequest.class)
public class CMD_Merchant extends Command<MerchantMessage.MerchantRequest> {

	@Override
	public void execute(MessageSource messageSource, MerchantMessage.MerchantRequest request) {
		String playerCode = messageSource.getTag();

		MerchantMessage.MerchantResponse.Builder response = MerchantMessage.MerchantResponse.newBuilder();

		new MerchantHandle().packResponse(playerCode, response);

		send(messageSource, response, Result.Success);
	}

	private void send(MessageSource messageSource, MerchantMessage.MerchantResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}